package Array;

import org.junit.Test;

import java.util.Arrays;

/**
 * @BelongsProject: SeniorArchitect-LeetCode
 * @BelongsPackage: Array
 * @Author: zhuangxiaoyan
 * @CreateTime: 2023-10-19  21:01
 * @Description: TODO
 * @Version: 1.0
 */
public class H指数274 {

    public int hIndex(int[] citations) {
        int h = 0;
        Arrays.sort(citations);
        int left = 0;
        int right = citations.length - 1;
        while (left <= right) {
            if (citations[left] < citations[right]) {
                int tmp = citations[right];
                citations[right] = citations[left];
                citations[left] = tmp;
            }
            left++;
            right--;

        }
        for (int i = 0; i < citations.length; i++) {
            if (i + 1 <= citations[i]) {
                h = i + 1;
            }
        }
        return h;
    }

    @Test
    public void tets() {
        int i = hIndex(new int[]{3,0,6,1,5});
        System.out.println(i);
    }
}
